import {isObject} from "@vueuse/core";

export const consts = {
    enum: {
        uploadType: {
            file: 0,
            hazard: 1
        }
    }
}

export function makeFormDataOptions(data) {
    const formData = new FormData()
    if (data && isObject(data)) {
        Object.keys(data).forEach(k => {
            const val = data[k]
            if (val) formData.append(k, val)
        })
    }
    return {
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data: formData
    }
}

export function appendDateRange(query, range, prop, start = 'Start', end = 'End') {
    if (range?.length) {
        query[prop + start] = range[0]
        query[prop + end] = range[1]
    }
    return query
}